<?php

/**
 * ECSHOP 专题前台
 * ============================================================================
 * 版权所有 2005-2011 热风科技，并保留所有权利。
 * 演示地址: http://palenggege.com  开发QQ:497401495    paleng
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * @author:     webboy <laupeng@163.com>
 * @version:    v2.1
 * ---------------------------------------------
 */

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(dirname(__FILE__) . '/includes/lib_order.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}
if($_REQUEST['act']=='list'){   
    /* 模板赋值 */
    assign_template();
    $position = assign_ur_here();
    $smarty->assign('page_title',       $position['title']);       // 页面标题
    $smarty->assign('ur_here',          $position['ur_here'] . '> ' . $topic['title']);     // 当前位置
    $smarty->assign('helps',            get_shop_help()); // 网店帮助  
    //查询店铺类目
    $sql_dpclass = "select * from ".$ecs->table('supplier_class')." order by sort desc";
    $info_dpclass = $db->getAll($sql_dpclass);
    $smarty->assign('info_dpclass', $info_dpclass);
    //
    $smarty->assign('class_id', $_GET['id']);
    $user_id = $GLOBALS['user_id'];
    if($_GET['id']){
    	$action = 'list&id='.$_GET['id'];
    }else{
    	$action = 'list';
    }
    $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
    $order_info = array();
    $sql = "SELECT COUNT(*) FROM " . $ecs->table('supplier') . " where apply_shop_type=2 and status=1 ";
    if($_GET['id']){
    	$sql .= "   and class_id='$_GET[id]'";
    }   
    $record_count = $db->getOne($sql);    
    $pager = get_pager('stores_xx.php', array(
    		'act' => $action
    ), $record_count, $page, 7);   
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('supplier')." where apply_shop_type=2 and status=1";
    if($_GET['id']){
    	$sql .= "   and class_id='$_GET[id]'";
    }
    $sql .= "   ORDER BY supplier_id DESC";   
    $res = $GLOBALS['db']->SelectLimit($sql, $pager['size'], $pager['start']);    
    while ($rows = $GLOBALS['db']->fetchRow($res))
    {
    	
    	
    	$sql_num= "select id from ".$ecs->table('order_stores')." where stores_id='$rows[supplier_id]' and is_paid=1";
    	$info_num = $db->getAll($sql_num);
    	
    	$msg[$rows['supplier_id']]['buy_num'] = count($info_num);
    	$msg[$rows['supplier_id']]['supplier_name'] = $rows['supplier_name'];
    	$msg[$rows['supplier_id']]['company_logo'] = $rows['company_logo'];
    	$msg[$rows['supplier_id']]['supplier_id'] = $rows['supplier_id'];
		$msg[$rows['supplier_id']]['address'] = $rows['address'];
		$msg[$rows['supplier_id']]['contacts_phone'] = $rows['contacts_phone'];
    }
    $smarty->assign('info', $msg);  
    $smarty->assign('pager', $pager);
    $smarty->display('stores_xx.dwt');
}
elseif($_REQUEST['act']=='list_two'){
	/* 模板赋值 */
	assign_template();
	$position = assign_ur_here();
	$smarty->assign('page_title',       $position['title']);       // 页面标题
	$smarty->assign('ur_here',          $position['ur_here'] . '> ' . $topic['title']);     // 当前位置
	$smarty->assign('helps',            get_shop_help()); // 网店帮助
	//查询店铺类目
	$sql = "select * from ".$ecs->table('supplier')." where supplier_id='$_GET[supplier_id]'";
	$info = $db->getRow($sql);
	
	if($info){
		$sql_1= 'SELECT region_name FROM ' . $ecs->table("region") . ' WHERE region_id='.$info[province].'';
		$info_res1 = $db->getRow($sql_1);
		
		$sql_2= 'SELECT region_name FROM ' . $ecs->table("region") . ' WHERE region_id='.$info[city].'';
		$info_res2 = $db->getRow($sql_2);
		
		$sql_3= 'SELECT region_name FROM ' . $ecs->table("region") . ' WHERE region_id='.$info[district].'';
		$info_res3 = $db->getRow($sql_3);
		
		$info['province']=$info_res1['region_name'];
		$info['city']=$info_res2['region_name'];
		$info['district']=$info_res3['region_name'];
		
	}

	
	
	$sql_num= "select id from ".$ecs->table('order_stores')." where stores_id='$_GET[supplier_id]' and is_paid=1";
	$info_num = $db->getAll($sql_num);
	 
	$info['buy_num'] = count($info_num);
	
	$smarty->assign('info', $info);
	
	$smarty->display('stores_xx_two.dwt');
}
elseif($_REQUEST['act']=='erweima'){
	

	include 'qrcode/phpqrcode.php';

		$value ='http://'.$_SERVER['SERVER_NAME'].'/mobile/user.php?act=stores_buy&supplier_id='.$_GET[supplier_id].'&ispay_zfbwx='.$_GET[ispay_zfbwx]; //二维码内容
		
	

	$errorCorrectionLevel = 'L';//容错级别
	$matrixPointSize = 5;//生成图片大小
	//生成二维码图片
	QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
	$logo = 'logo.png';//准备好的logo图片
	$QR = 'qrcode.png';//已经生成的原始二维码图
	 
	if ($logo !== FALSE) {
		$QR = imagecreatefromstring(file_get_contents($QR));
		$logo = imagecreatefromstring(file_get_contents($logo));
		$QR_width = imagesx($QR);//二维码图片宽度
		$QR_height = imagesy($QR);//二维码图片高度
		$logo_width = imagesx($logo);//logo图片宽度
		$logo_height = imagesy($logo);//logo图片高度
		$logo_qr_width = $QR_width / 5;
		$scale = $logo_width/$logo_qr_width;
		$logo_qr_height = $logo_height/$scale;
		$from_width = ($QR_width - $logo_qr_width) / 2;
		//重新组合图片并调整大小
		imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
		$logo_qr_height, $logo_width, $logo_height);
	}
	//输出图片
	imagepng($QR, 'helloweixin.png');
	
	if($_GET['ispay_zfbwx']==1){
		echo '<div style="text-align: center;margin-top:200px">支付宝收款码</div>';
	}else{
		echo '<div style="text-align: center;margin-top:200px">微信收款码</div>';
	}
	
	echo '<div style="text-align: center;margin-top:10px"><img src="helloweixin.png"></div>';
	


	
}
elseif($_REQUEST['act']=='list_buy'){
	/* 模板赋值 */
	assign_template();
	$position = assign_ur_here();
	$smarty->assign('page_title',       $position['title']);       // 页面标题
	$smarty->assign('ur_here',          $position['ur_here'] . '> ' . $topic['title']);     // 当前位置
	$smarty->assign('helps',            get_shop_help()); // 网店帮助
	
	$sql = "select * from ".$ecs->table('supplier')." where supplier_id='$_GET[supplier_id]'";
	$info = $db->getRow($sql);
	$smarty->assign('info', $info);
	$smarty->display('stores_xx_buy.dwt');
}
elseif($_REQUEST['act']=='jisuan'){
	$yhqid=$_GET['id'];
	$sql = "select * from ".$ecs->table('bonus_type')." where type_id='$yhqid'";
	$info = $db->getRow($sql);
	
	$yhq=$info['type_money'];
	$keyongyuer=$_GET['keyongyeer'];
	$zongjia=$_GET['zongjia'];	
	$jifen=$_GET['jifen']*0.7;
	$zuihou=$zongjia-$keyongyuer-$yhq-$jifen;
	
	
	
	echo $zuihou;
	exit;
	
	
}
elseif($_REQUEST['act']=='buy_dan'){

		$Loaction = 'user.php';
	
		if (!$_SESSION['user_id'])
		{
			ecs_header("Location: $Loaction\n");
	
			exit;
		}
		/* 模板赋值 */
		assign_template();
		$position = assign_ur_here();
		$smarty->assign('page_title',       $position['title']);       // 页面标题
		$smarty->assign('ur_here',          $position['ur_here'] . '> ' . $topic['title']);     // 当前位置
		$smarty->assign('helps',            get_shop_help()); // 网店帮助


		$user_id = $_SESSION['user_id'];
	
			$action = 'buy_dan';
		
		$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
		$order_info = array();
		$sql = "SELECT COUNT(*) FROM " . $ecs->table('order_stores') . " where is_paid=1 and user_id=$user_id";
	
		$record_count = $db->getOne($sql);
		$pager = get_pager('stores_xx.php', array(
				'act' => $action
		), $record_count, $page, 7);
		$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('order_stores')." where is_paid=1 and user_id=$user_id";

		$sql .= "   ORDER BY id DESC";
		$res = $GLOBALS['db']->SelectLimit($sql, $pager['size'], $pager['start']);
		while ($rows = $GLOBALS['db']->fetchRow($res))
		{
			
			$sql_sjname = "SELECT supplier_name FROM " . $GLOBALS['ecs']->table('supplier') .
			" WHERE supplier_id = '$rows[stores_id]'";
			$infosjname = $GLOBALS['db']->getRow($sql_sjname);
			
			
			
			$msg[$rows['id']]['supplier_name'] = $infosjname['supplier_name'];
			$msg[$rows['id']]['id'] = $rows['id'];
			$msg[$rows['id']]['order_amount'] = $rows['order_amount'];
			$msg[$rows['id']]['amount'] = $rows['amount'];
			$msg[$rows['id']]['payment'] = $rows['payment'];
			$msg[$rows['id']]['paid_time'] = local_date('Y-m-d H:i', $rows['paid_time']);
		}
		$smarty->assign('info', $msg);
		$smarty->assign('pager', $pager);
		$smarty->display('buy_dan.dwt');
}
elseif($_REQUEST['act']=='buy_tc'){

	$Loaction = 'user.php';

	if (!$_SESSION['user_id'])
	{
		ecs_header("Location: $Loaction\n");

		exit;
	}
	/* 模板赋值 */
	assign_template();
	$position = assign_ur_here();
	$smarty->assign('page_title',       $position['title']);       // 页面标题
	$smarty->assign('ur_here',          $position['ur_here'] . '> ' . $topic['title']);     // 当前位置
	$smarty->assign('helps',            get_shop_help()); // 网店帮助


	$user_id = $_SESSION['user_id'];

	$action = 'buy_tc';

	$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
	$order_info = array();
	
	if($_GET['shopid']){
		$sql = "SELECT COUNT(*) FROM " . $ecs->table('supplier_rebate_log') . " where user_id=$user_id and order_id='$_GET[shopid]'";
	}else{
		$sql = "SELECT COUNT(*) FROM " . $ecs->table('supplier_rebate_log') . " where user_id=$user_id";
	}
	
	

	$record_count = $db->getOne($sql);
	$pager = get_pager('stores_xx.php', array(
			'act' => $action
	), $record_count, $page, 7);
	if($_GET['shopid']){
		$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('supplier_rebate_log')." where user_id=$user_id and order_id='$_GET[shopid]'";
	}else{
		$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('supplier_rebate_log')." where user_id=$user_id";
	}
	

	$sql .= "   ORDER BY rebate_log_id DESC";
	$res = $GLOBALS['db']->SelectLimit($sql, $pager['size'], $pager['start']);
	while ($rows = $GLOBALS['db']->fetchRow($res))
	{
			
		$sql_sjname = "SELECT supplier_name FROM " . $GLOBALS['ecs']->table('supplier') .
		" WHERE supplier_id = '$rows[supplier_id]'";
		$infosjname = $GLOBALS['db']->getRow($sql_sjname);
			
			
			
		$msg[$rows['rebate_log_id']]['supplier_name'] = $infosjname['supplier_name'];
		$msg[$rows['rebate_log_id']]['order_id'] = $rows['order_id'];

		$msg[$rows['rebate_log_id']]['user_tcjf'] = $rows['user_tcjf'];
		$msg[$rows['rebate_log_id']]['sj_tcmoney'] = $rows['rebate_money'];
		$msg[$rows['rebate_log_id']]['pt_tcmoney'] = $rows['all_money'];
		$msg[$rows['rebate_log_id']]['user_tcyhq'] = $rows['user_tcyhq'];
		
		$msg[$rows['rebate_log_id']]['add_time'] = local_date('Y-m-d H:i', $rows['add_time']);
	}
	$smarty->assign('info', $msg);
	$smarty->assign('pager', $pager);
	$smarty->display('buy_tc.dwt');
}

?>